﻿using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace GrailTechnology.AutoTags.Providers
{
    public static class Extensions
    {
        public static string[] ArrayConcat(char delimiter, IEnumerable<string[]> arrays)
        {
            var list = new List<string>();

            foreach (string[] array in arrays)
            {
                if (array != null && array.Length > 0)
                {
                    list.AddRange(array.Where(v => !string.IsNullOrEmpty(v)));
                }
            }

            return list.ToArray();
        }

        public static TagTheNetResponse ToTagTheNetReponse(this string jsonResponse)
        {
            var jsonObject = JObject.Parse(jsonResponse);

            var json = jsonObject["memes"][0]["dimensions"];

            return JsonConvert.DeserializeObject<TagTheNetResponse>(json.ToString());
        }
    }
}
